package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.StreetBiz;
import guda.stark.dal.dao.StreetDAO;
import guda.stark.dal.dataobject.StreetDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class StreetBizImpl implements StreetBiz{

    private final static Logger logger = LoggerFactory.getLogger(StreetBizImpl.class);

    @Autowired
    private StreetDAO streetDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            StreetDO streetDO = streetDAO.getStreetById(id);
            bizResult.data.put("streetDO", streetDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query Street error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = streetDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<StreetDO> streetList = streetDAO.selectForPage(baseQuery);
            bizResult.data.put("streetList", streetList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view Street list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            streetDAO.delStreetById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete street error", e);
        }
        return bizResult;
    }

    public BizResult create(StreetDO streetDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = streetDAO.insert(streetDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create Street error", e);
        }
        return bizResult;
    }




}
